var boxy;

function errorTips(message){
	$.ckBoxy({
		width:450,
		height:240,
		title:"提示",
		content:
	    '<div class="bd">'+
	    '<p class="lh25 mt30 mb20 tc vm f14 c_777">'+
		'<img alt="" src="http://res.ckimg.com/sites/www/v2/images/public/ico_error_24x24.png" class="vm mr10">'+
		'<span>'+message+'</span>'+
		'</p><div class="tc">'+
		'</div></div>'
	});		
}

function quizImageView(url){
	$.ckBoxy({
		width:710,
		height:500,
		title:"图片预览<span style='font-size:12px;'>(点击图片可查看原图)</span>",
		content:
	    '<div class="bd">'+
	    '<p class="lh25 mt30 mb20 tc vm f14 c_777">'+
		'<a href="'+url+'" target="_blank"><img style="max-width:650px;max-height:400px;" src="'+url+'" title="查看原图"></a>'+
		'</p><div class="tc">'+
		'</div></div>'
	});	
}


function delQuestion(qid){
	$.ajax({
		url:"/?mod=quiz&act=quizlib&do=delete",
		type:"get",
		dataType:"json",
		data:"qid="+qid+"&tm="+new Date().getTime(),
		success:function(ret){
			if(ret.code == 0){
				window.location.reload();
			}else{
				boxy.cancel();
				errorTips(ret.data);
			}
		}
	});
}

function delAsk(qid){
	boxy = $.ckBoxy({
		width:450,
		height:240,
		title:"提示",
		content:
	    '<div class="bd">'+
	    '<p class="lh25 mt30 mb20 tc vm f14 c_777">'+
		'<img alt="" src="http://res.ckimg.com/sites/www/v2/images/public/ico_warning_24x24.png" class="vm mr10">'+
		'<span>确定删除试题？所有相关联的测试上的这道题目会被删除。</span>'+
		'</p><div class="tc">'+
		'<a class="c_btn30 mr20 submit" href="javascript:;" onclick="delQuestion('+qid+');"><span>确定</span></a>'+
		'<a class="c_btn30 cancel" href="javascript:;"><span>取消</span></a>'+
		'</div></div>',
		callback:function(){
			$('a.cancel').click(function(){
				boxy.cancel();
			});
		}
	});		
}

$(function(){
	
	$('a[del]').click(function(){
		delAsk($(this).attr('del'));
	});
	
	$('span.stxj').click(function(){
		if($(this).hasClass('zk')){
			$(this).parent().parent().next().hide();
			$(this).removeClass('zk');
		}else{
			$(this).parent().parent().next().show();
			$(this).addClass('zk');
		}
	});
	
});